Skip to content

security: add CSP and security headers to console-ui (SEC-014) - #213

Merged
Gajesh2007 merged 1 commit into
masterfrom
security/console-security-headers
May 25, 2026
Merged

Gajesh2007 merged 1 commit into
masterfrom
security/console-security-headers

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented May 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds six security headers to all console-ui routes via next.config.ts headers(). Closes the open finding SEC-014 (threat T-019: missing security headers increase XSS blast radius).

Headers Added

Header Value Purpose
Content-Security-Policy See below Restricts script/style/connect/frame origins
X-Frame-Options DENY Clickjacking prevention (legacy)
X-Content-Type-Options nosniff MIME-type sniffing prevention
Referrer-Policy strict-origin-when-cross-origin Controls referrer leakage
Strict-Transport-Security max-age=63072000; includeSubDomains; preload Forces HTTPS
Permissions-Policy camera=(), microphone=(), geolocation=() Denies device access

CSP Directives

Directive Value Why
default-src 'self' Baseline restriction
script-src 'self' 'unsafe-inline' 'unsafe-eval' googletagmanager stripe.js Privy SDK + Next.js require unsafe-inline/eval
style-src 'self' 'unsafe-inline' Next.js injected styles
img-src 'self' data: blob: https: Data URIs + external images
font-src 'self' data: Inline fonts
connect-src 'self' api.darkbloom.dev *.privy.io google-analytics stripe API + auth + analytics
frame-src auth.privy.io js.stripe.com Privy auth + Stripe Checkout iframes
frame-ancestors 'none' Prevents embedding in iframes
base-uri 'self' Prevents base tag hijacking
form-action 'self' Restricts form submission targets

Verification

  • npm run build passes
  • Headers apply to all routes via /(.*) source pattern

Notes

  • unsafe-inline and unsafe-eval in script-src are required by the Privy SDK and Next.js runtime. A future improvement would be moving to nonce-based CSP.
  • The CSP is deliberately tight on connect-src and frame-src -- if new external services are added, their origins must be allowlisted here.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.

Add Content-Security-Policy, X-Frame-Options, X-Content-Type-Options,
Referrer-Policy, Strict-Transport-Security, and Permissions-Policy
headers to all console-ui routes via next.config.ts headers().

CSP directives:
- default-src 'self'
- script-src: self + Google Tag Manager + Stripe.js
- connect-src: self + coordinator API + Privy auth + GA + Stripe API
- frame-src: Privy auth iframes + Stripe Checkout iframes
- frame-ancestors 'none' (clickjacking prevention)
- img-src: self + data/blob + https (for external avatars/icons)

Other headers:
- X-Frame-Options: DENY (legacy clickjacking prevention)
- X-Content-Type-Options: nosniff (MIME sniffing prevention)
- Referrer-Policy: strict-origin-when-cross-origin
- HSTS: max-age=63072000 with includeSubDomains and preload
- Permissions-Policy: deny camera, microphone, geolocation

Closes SEC-014 (T-019).
@vercel

vercel Bot commented May 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview May 25, 2026 8:40pm
d-inference-console-ui-dev Ready Ready Preview May 25, 2026 8:40pm
d-inference-landing Ready Ready Preview May 25, 2026 8:40pm

Request Review

@github-actions

github-actions Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results

Runner: macos-15 (M1 Virtual) | Date: 2026-05-25 20:42 UTC

1-provider-streaming

1 providers, 1 users, 30 requests, concurrency=5, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 1 0.5 GB
Metric Value
Total Requests 30
Success 4
Errors 26
Total Duration 4.976s
Throughput 0.8 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 4 1.764s 1.764s 1.764s 1.764s
parse 4 80µs 107µs 110µs 110µs
reserve 4 8ms 9ms 10ms 10ms
route 4 37µs 38µs 77µs 77µs
encrypt 4 734µs 793µs 908µs 908µs
dispatch 4 55µs 58µs 65µs 65µs
coordinator_to_provider 4 1.748s 1.749s 1.751s 1.751s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=79.75µs (threshold=1ms)
parse:p95<=5ms PASS p95=110µs (threshold=5ms)
reserve:mean<=50ms PASS mean=7.683ms (threshold=50ms)
reserve:p95<=200ms PASS p95=10.49ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=734.25µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=908µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=54.75µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=65µs (threshold=50ms)

1-provider-non-streaming

1 providers, 1 users, 20 requests, concurrency=5, streaming=false

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 1 0.5 GB
Metric Value
Total Requests 20
Success 4
Errors 16
Total Duration 3.279s
Throughput 1.2 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 4 3.275s 3.276s 3.279s 3.279s
parse 4 45µs 70µs 76µs 76µs
reserve 4 4ms 4ms 6ms 6ms
route 4 11µs 11µs 17µs 17µs
encrypt 4 456µs 458µs 523µs 523µs
dispatch 4 29µs 28µs 38µs 38µs
coordinator_to_provider 4 1.719s 1.72s 1.721s 1.721s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=45µs (threshold=1ms)
parse:p95<=5ms PASS p95=76µs (threshold=5ms)
reserve:mean<=50ms PASS mean=3.796ms (threshold=50ms)
reserve:p95<=200ms PASS p95=5.538ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=455.5µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=523µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=29.25µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=38µs (threshold=50ms)

7-provider-multi-model

7 providers, 5 users, 50 requests, concurrency=10, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 4 0.5 GB
mlx-community/gemma-3-270m-4bit 3 0.2 GB
Metric Value
Total Requests 50
Success 50
Errors 0
Total Duration 15.104s
Throughput 3.3 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 50 763ms 187ms 4.078s 4.079s
parse 48 29µs 22µs 70µs 95µs
reserve 48 2ms 1ms 3ms 4ms
route 48 29µs 25µs 71µs 84µs
encrypt 50 1ms 1ms 1ms 1ms
dispatch 50 47µs 38µs 100µs 199µs
coordinator_to_provider 50 658ms 184ms 3.933s 4.07s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=28.625µs (threshold=1ms)
parse:p95<=5ms PASS p95=70µs (threshold=5ms)
reserve:mean<=50ms PASS mean=1.780208ms (threshold=50ms)
reserve:p95<=200ms PASS p95=3.493ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=546.56µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=806µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=46.56µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=100µs (threshold=50ms)

3-provider-high-concurrency

3 providers, 10 users, 60 requests, concurrency=20, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 3 0.5 GB
Metric Value
Total Requests 60
Success 12
Errors 48
Total Duration 3.423s
Throughput 3.5 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 12 1.94s 1.948s 1.951s 1.951s
parse 12 29µs 27µs 48µs 48µs
reserve 12 5ms 5ms 8ms 8ms
route 12 28µs 25µs 73µs 73µs
encrypt 12 1ms 1ms 1ms 1ms
dispatch 12 37µs 30µs 88µs 88µs
coordinator_to_provider 12 1.915s 1.923s 1.928s 1.928s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=28.583µs (threshold=1ms)
parse:p95<=5ms PASS p95=48µs (threshold=5ms)
reserve:mean<=50ms PASS mean=5.161166ms (threshold=50ms)
reserve:p95<=200ms PASS p95=7.61ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=913.333µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=1.162ms (threshold=50ms)
dispatch:mean<=5ms PASS mean=37.25µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=88µs (threshold=50ms)

1-provider-queue-saturation

1 providers, 10 users, 40 requests, concurrency=15, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 1 0.5 GB
Metric Value
Total Requests 40
Success 4
Errors 36
Total Duration 3.706s
Throughput 1.1 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 4 2.096s 2.096s 2.097s 2.097s
parse 4 14µs 12µs 19µs 19µs
reserve 4 2ms 3ms 3ms 3ms
route 4 12µs 13µs 23µs 23µs
encrypt 4 676µs 654µs 858µs 858µs
dispatch 4 15µs 16µs 18µs 18µs
coordinator_to_provider 4 2.09s 2.09s 2.091s 2.091s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=13.5µs (threshold=1ms)
parse:p95<=5ms PASS p95=19µs (threshold=5ms)
reserve:mean<=50ms PASS mean=2.3295ms (threshold=50ms)
reserve:p95<=200ms PASS p95=2.58ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=676µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=858µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=14.75µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=18µs (threshold=50ms)

3-provider-20-users

3 providers, 20 users, 60 requests, concurrency=10, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 3 0.5 GB
Metric Value
Total Requests 60
Success 60
Errors 0
Total Duration 9.457s
Throughput 6.3 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 60 398ms 61ms 2.072s 2.072s
parse 60 20µs 17µs 44µs 54µs
reserve 60 1ms 1ms 3ms 3ms
route 60 20µs 20µs 30µs 62µs
encrypt 60 405µs 388µs 579µs 657µs
dispatch 60 46µs 34µs 131µs 280µs
coordinator_to_provider 60 395ms 59ms 2.064s 2.067s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=19.75µs (threshold=1ms)
parse:p95<=5ms PASS p95=44µs (threshold=5ms)
reserve:mean<=50ms PASS mean=1.424816ms (threshold=50ms)
reserve:p95<=200ms PASS p95=2.553ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=404.85µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=579µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=46.166µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=131µs (threshold=50ms)

1-provider-scaling

1 providers, 5 users, 30 requests, concurrency=10, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 1 0.5 GB
Metric Value
Total Requests 30
Success 4
Errors 26
Total Duration 3.402s
Throughput 1.2 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 4 2.197s 2.197s 2.197s 2.197s
parse 4 12µs 13µs 17µs 17µs
reserve 4 2ms 2ms 2ms 2ms
route 4 14µs 16µs 18µs 18µs
encrypt 4 518µs 433µs 881µs 881µs
dispatch 4 27µs 28µs 37µs 37µs
coordinator_to_provider 4 2.192s 2.192s 2.192s 2.192s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=12µs (threshold=1ms)
parse:p95<=5ms PASS p95=17µs (threshold=5ms)
reserve:mean<=50ms PASS mean=1.8895ms (threshold=50ms)
reserve:p95<=200ms PASS p95=2.058ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=518.25µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=881µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=26.75µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=37µs (threshold=50ms)

3-provider-scaling

3 providers, 5 users, 30 requests, concurrency=10, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 3 0.5 GB
Metric Value
Total Requests 30
Success 30
Errors 0
Total Duration 5.772s
Throughput 5.2 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 30 775ms 131ms 2.196s 2.196s
parse 30 20µs 17µs 48µs 74µs
reserve 30 2ms 1ms 6ms 6ms
route 30 26µs 19µs 72µs 75µs
encrypt 30 1ms 0s 1ms 1ms
dispatch 30 36µs 30µs 66µs 150µs
coordinator_to_provider 30 767ms 127ms 2.177s 2.177s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=20.2µs (threshold=1ms)
parse:p95<=5ms PASS p95=48µs (threshold=5ms)
reserve:mean<=50ms PASS mean=2.237266ms (threshold=50ms)
reserve:p95<=200ms PASS p95=6.058ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=547.566µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=903µs (threshold=50ms)
dispatch:mean<=5ms PASS mean=35.8µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=66µs (threshold=50ms)

5-provider-scaling

5 providers, 5 users, 30 requests, concurrency=10, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 5 0.5 GB
Metric Value
Total Requests 30
Success 30
Errors 0
Total Duration 6.782s
Throughput 4.4 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 30 803ms 11ms 2.382s 2.383s
parse 30 21µs 16µs 45µs 92µs
reserve 30 2ms 2ms 3ms 3ms
route 30 23µs 21µs 54µs 79µs
encrypt 30 1ms 0s 1ms 1ms
dispatch 30 32µs 28µs 78µs 78µs
coordinator_to_provider 30 798ms 6ms 2.375s 2.376s

Assertion Report: PASS

Assertion Result Detail
parse:mean<=1ms PASS mean=21.433µs (threshold=1ms)
parse:p95<=5ms PASS p95=45µs (threshold=5ms)
reserve:mean<=50ms PASS mean=1.816166ms (threshold=50ms)
reserve:p95<=200ms PASS p95=2.799ms (threshold=200ms)
encrypt:mean<=5ms PASS mean=538.133µs (threshold=5ms)
encrypt:p95<=50ms PASS p95=1.159ms (threshold=50ms)
dispatch:mean<=5ms PASS mean=32.266µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=78µs (threshold=50ms)

3-provider-heavy-100conc-10kb

3 providers, 20 users, 100 requests, concurrency=100, streaming=true

Model Providers RAM
mlx-community/Qwen3.5-0.8B-MLX-4bit 3 0.5 GB
Metric Value
Total Requests 100
Success 12
Errors 88
Total Duration 3.842s
Throughput 3.1 req/s

Latency Decomposition

Segment Count Mean P50 P95 Max
total_e2e 12 2.217s 2.218s 2.23s 2.23s
parse 12 95µs 97µs 123µs 123µs
reserve 12 8ms 8ms 9ms 9ms
route 12 16µs 17µs 27µs 27µs
encrypt 12 18ms 18ms 18ms 18ms
dispatch 12 33µs 33µs 44µs 44µs
coordinator_to_provider 12 2.178s 2.179s 2.191s 2.191s

Assertion Report: FAIL

Assertion Result Detail
parse:mean<=1ms PASS mean=94.75µs (threshold=1ms)
parse:p95<=5ms PASS p95=123µs (threshold=5ms)
reserve:mean<=50ms PASS mean=8.321333ms (threshold=50ms)
reserve:p95<=200ms PASS p95=8.655ms (threshold=200ms)
encrypt:mean<=5ms FAIL mean=17.6685ms (threshold=5ms)
encrypt:p95<=50ms PASS p95=18.417ms (threshold=50ms)
dispatch:mean<=5ms PASS mean=33.416µs (threshold=5ms)
dispatch:p95<=50ms PASS p95=44µs (threshold=50ms)

@Gajesh2007
Gajesh2007 merged commit 211bb88 into master May 25, 2026
17 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 562b16a71c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread console-ui/next.config.ts
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https:",
"font-src 'self' data:",
"connect-src 'self' https://api.darkbloom.dev https://*.privy.io wss://*.privy.io https://www.google-analytics.com https://api.stripe.com",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow non-default coordinator origins in connect-src

The new CSP hardcodes connect-src to https://api.darkbloom.dev, but the UI intentionally supports alternate coordinator endpoints (for example via localStorage.getItem("darkbloom_coordinator_url") and NEXT_PUBLIC_COORDINATOR_URL in provider pages) and then issues browser-side fetch calls to that dynamic origin. With this header, any non-default deployment/dev environment will have those requests blocked by CSP, breaking flows like provider dashboard and earnings outside api.darkbloom.dev.

Useful? React with 👍 / 👎.

This branch was successfully deployed

3 active deployments
Preview – d-inference — 562b16a7 Deployed May 25, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 562b16a7 Deployed May 25, 2026 by vercel[bot]
Preview – d-inference-landing — 562b16a7 Deployed May 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant